colorchooser: Stop using ::popup-menu
authorMatthias Clasen <mclasen@redhat.com>
Thu, 19 Mar 2020 02:36:31 +0000 (22:36 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 26 Mar 2020 03:14:44 +0000 (23:14 -0400)
This signal is going away. Use an action instead.

gtk/gtkcoloreditor.c
gtk/gtkcolorplane.c
gtk/gtkcolorscale.c
gtk/ui/gtkcoloreditor.ui

index 6f3ac11b6d6953244a2e7bfd40b9acd4b0fd076c..9fb73fa027cbfd7f4c69f8724e56f8eb4bf91bfe 100644 (file)
@@ -189,35 +189,44 @@ dismiss_current_popup (GtkColorEditor *editor)
 }
 
 static void
-popup_edit (GtkWidget      *widget,
-            GtkColorEditor *editor)
+popup_edit (GtkWidget  *widget,
+            const char *action_name,
+            GVariant   *parameters)
 {
+  GtkColorEditor *editor = GTK_COLOR_EDITOR (widget);
   GtkWidget *popup = NULL;
   GtkRoot *root;
   GtkWidget *focus;
   gint position;
   gint s, e;
+  const char *param;
+
+  param = g_variant_get_string (parameters, NULL);
 
-  if (widget == editor->priv->sv_plane)
+  if (strcmp (param, "sv") == 0)
     {
       popup = editor->priv->sv_popup;
       focus = editor->priv->s_entry;
       position = 0;
     }
-  else if (widget == editor->priv->h_slider)
+  else if (strcmp (param, "h") == 0)
     {
       popup = editor->priv->h_popup;
       focus = editor->priv->h_entry;
       gtk_range_get_slider_range (GTK_RANGE (editor->priv->h_slider), &s, &e);
       position = (s + e) / 2;
     }
-  else if (widget == editor->priv->a_slider)
+  else if (strcmp (param, "a") == 0)
     {
       popup = editor->priv->a_popup;
       focus = editor->priv->a_entry;
       gtk_range_get_slider_range (GTK_RANGE (editor->priv->a_slider), &s, &e);
       position = (s + e) / 2;
     }
+  else
+    {
+      g_warning ("unsupported popup_edit parameter %s", param);
+    }
 
   if (popup == editor->priv->current_popup)
     dismiss_current_popup (editor);
@@ -544,8 +553,12 @@ gtk_color_editor_class_init (GtkColorEditorClass *class)
   gtk_widget_class_bind_template_callback (widget_class, entry_text_changed);
   gtk_widget_class_bind_template_callback (widget_class, entry_apply);
   gtk_widget_class_bind_template_callback (widget_class, entry_focus_changed);
-  gtk_widget_class_bind_template_callback (widget_class, popup_edit);
   gtk_widget_class_bind_template_callback (widget_class, pick_color);
+
+  gtk_widget_class_install_action (widget_class, "color.edit", "s", popup_edit);
+  gtk_widget_class_install_action (widget_class, "color.edit", "s", popup_edit);
+  gtk_widget_class_install_action (widget_class, "color.edit", "s", popup_edit);
+
 }
 
 static void
index c73b9eec22829eec5bbf63a72f22ebcb7324033e..36a9ca6b8efd428aa5821adffe9d41384a671695 100644 (file)
 #include "gtksnapshot.h"
 #include "gtkprivate.h"
 #include "gtkeventcontrollerkey.h"
+#include "gtkshortcutcontroller.h"
+#include "gtkshortcuttrigger.h"
+#include "gtkshortcutaction.h"
+#include "gtkshortcut.h"
 
 struct _GtkColorPlanePrivate
 {
@@ -244,11 +248,11 @@ static void
 hold_action (GtkGestureLongPress *gesture,
              gdouble              x,
              gdouble              y,
-             GtkColorPlane       *plane)
+             GtkWidget           *plane)
 {
-  gboolean handled;
-
-  g_signal_emit_by_name (plane, "popup-menu", &handled);
+  gtk_widget_activate_action (plane,
+                              "color.edit",
+                              "s", gtk_widget_get_name (plane));
 }
 
 static void
@@ -344,7 +348,7 @@ static void
 plane_drag_gesture_begin (GtkGestureDrag *gesture,
                           gdouble         start_x,
                           gdouble         start_y,
-                          GtkColorPlane  *plane)
+                          GtkWidget      *plane)
 {
   guint button;
 
@@ -352,9 +356,9 @@ plane_drag_gesture_begin (GtkGestureDrag *gesture,
 
   if (button == GDK_BUTTON_SECONDARY)
     {
-      gboolean handled;
-
-      g_signal_emit_by_name (plane, "popup-menu", &handled);
+      gtk_widget_activate_action (plane,
+                                  "color.edit",
+                                  "s", gtk_widget_get_name (plane));
     }
 
   if (button != GDK_BUTTON_PRIMARY)
@@ -363,9 +367,9 @@ plane_drag_gesture_begin (GtkGestureDrag *gesture,
       return;
     }
 
-  set_cross_cursor (GTK_WIDGET (plane), TRUE);
-  update_color (plane, start_x, start_y);
-  gtk_widget_grab_focus (GTK_WIDGET (plane));
+  set_cross_cursor (plane, TRUE);
+  update_color (GTK_COLOR_PLANE (plane), start_x, start_y);
+  gtk_widget_grab_focus (plane);
   gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
 }
 
@@ -397,6 +401,9 @@ gtk_color_plane_init (GtkColorPlane *plane)
   GtkEventController *controller;
   GtkGesture *gesture;
   AtkObject *atk_obj;
+  GtkShortcutTrigger *trigger;
+  GtkShortcutAction *action;
+  GtkShortcut *shortcut;
 
   plane->priv = gtk_color_plane_get_instance_private (plane);
 
@@ -430,6 +437,14 @@ gtk_color_plane_init (GtkColorPlane *plane)
   g_signal_connect (controller, "key-pressed",
                     G_CALLBACK (key_controller_key_pressed), plane);
   gtk_widget_add_controller (GTK_WIDGET (plane), controller);
+
+  controller = gtk_shortcut_controller_new ();
+  trigger = gtk_alternative_trigger_new (gtk_keyval_trigger_new (GDK_KEY_F10, GDK_SHIFT_MASK),
+                                         gtk_keyval_trigger_new (GDK_KEY_Menu, 0));
+  action = gtk_action_action_new ("color.edit");
+  shortcut = gtk_shortcut_new_with_arguments (trigger, action, "s", "sv");
+  gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut);
+  gtk_widget_add_controller (GTK_WIDGET (plane), controller);
 }
 
 static void
index d4bc48452ab6218f28f2f8d104480ce81d22fbd1..56d120b1114b6270d4dd629c869e9ed6ae19cfd6 100644 (file)
 #include "gtkprivate.h"
 #include "gtkintl.h"
 #include "gtksnapshot.h"
+#include "gtkshortcutcontroller.h"
+#include "gtkshortcuttrigger.h"
+#include "gtkshortcutaction.h"
+#include "gtkshortcut.h"
 
 #include <math.h>
 
@@ -48,7 +52,7 @@ enum
 static void hold_action (GtkGestureLongPress *gesture,
                          gdouble              x,
                          gdouble              y,
-                         GtkColorScale       *scale);
+                         GtkWidget           *scale);
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkColorScale, gtk_color_scale, GTK_TYPE_SCALE)
 
@@ -160,6 +164,29 @@ gtk_color_scale_init (GtkColorScale *scale)
   gtk_widget_add_css_class (GTK_WIDGET (scale), "color");
 }
 
+static void
+scale_constructed (GObject *object)
+{
+  GtkColorScale *scale = GTK_COLOR_SCALE (object);
+  GtkColorScalePrivate *priv = gtk_color_scale_get_instance_private (scale);
+  GtkEventController *controller;
+  GtkShortcutTrigger *trigger;
+  GtkShortcutAction *action;
+  GtkShortcut *shortcut;
+
+  controller = gtk_shortcut_controller_new ();
+  trigger = gtk_alternative_trigger_new (gtk_keyval_trigger_new (GDK_KEY_F10, GDK_SHIFT_MASK),
+                                         gtk_keyval_trigger_new (GDK_KEY_Menu, 0));
+  action = gtk_action_action_new ("color.edit");
+  shortcut = gtk_shortcut_new_with_arguments (trigger,
+                                              action,
+                                              "s",
+                                              priv->type == GTK_COLOR_SCALE_ALPHA
+                                                ? "a" : "h");
+  gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut);
+  gtk_widget_add_controller (GTK_WIDGET (scale), controller);
+}
+
 static void
 scale_get_property (GObject    *object,
                     guint       prop_id,
@@ -223,11 +250,11 @@ static void
 hold_action (GtkGestureLongPress *gesture,
              gdouble              x,
              gdouble              y,
-             GtkColorScale       *scale)
+             GtkWidget           *scale)
 {
-  gboolean handled;
-
-  g_signal_emit_by_name (scale, "popup-menu", &handled);
+  gtk_widget_activate_action (scale,
+                              "color.edit",
+                              "s", gtk_widget_get_name (scale));
 }
 
 static void
@@ -245,6 +272,7 @@ gtk_color_scale_class_init (GtkColorScaleClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
 
+  object_class->constructed = scale_constructed;
   object_class->finalize = scale_finalize;
   object_class->get_property = scale_get_property;
   object_class->set_property = scale_set_property;
@@ -253,6 +281,7 @@ gtk_color_scale_class_init (GtkColorScaleClass *class)
       g_param_spec_int ("scale-type", P_("Scale type"), P_("Scale type"),
                         0, 1, 0,
                         GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
 }
 
 void
index 4075102a5e2bdada90c4b7fbdad06dc13f971e04..d03b287278993f528bd3ee1e99e11bf077bc96cb 100644 (file)
             </child>
             <child>
               <object class="GtkColorScale" id="h_slider">
+                <property name="name">h</property>
                 <property name="can-focus">True</property>
                 <property name="orientation">vertical</property>
                 <property name="adjustment">h_adj</property>
                 <property name="draw-value">False</property>
                 <property name="has-origin">False</property>
-                <signal name="popup-menu" handler="popup_edit" swapped="no"/>
                 <layout>
                   <property name="left-attach">0</property>
                   <property name="top-attach">1</property>
@@ -97,6 +97,7 @@
             </child>
             <child>
               <object class="GtkColorScale" id="a_slider">
+                <property name="name">a</property>
                 <property name="can-focus">True</property>
                 <property name="adjustment">a_adj</property>
                 <property name="draw-value">False</property>
                 <style>
                   <class name="marks-before"/>
                 </style>
-                <signal name="popup-menu" handler="popup_edit" swapped="no"/>
                 <layout>
                   <property name="left-attach">1</property>
                   <property name="top-attach">2</property>
             </child>
             <child>
               <object class="GtkColorPlane" id="sv_plane">
+                <property name="name">sv</property>
                 <property name="width-request">300</property>
                 <property name="height-request">300</property>
                 <property name="can-focus">True</property>
                 <property name="h-adjustment">h_adj</property>
                 <property name="s-adjustment">s_adj</property>
                 <property name="v-adjustment">v_adj</property>
-                <signal name="popup-menu" handler="popup_edit" swapped="no"/>
                 <layout>
                   <property name="left-attach">1</property>
                   <property name="top-attach">1</property>